package GUI;

import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;


public class admUI extends JPanel implements ActionListener {
     private JButton add_test,add_stu,add_tea;
     private JButton del_test,del_stu,del_tea;
     private JButton mod_test,mod_stu,mod_tea;
     JFrame jf = new JFrame("考试管理系统---管理员界面");
     public admUI() {
         jf.setLayout(null);
         jf.setResizable(false);//固定窗口不可变
         jf.setLocationRelativeTo(null);//窗口居中
         jf.setLocation(55, 60);
         jf.setVisible(true);//可见
         jf.setSize(1360, 680);//大小
         jf.setDefaultCloseOperation(jf.DISPOSE_ON_CLOSE);
         option();//选项卡
     }
     public void option(){
         JTabbedPane jt = new JTabbedPane(JTabbedPane.LEFT,JTabbedPane.SCROLL_TAB_LAYOUT);//选项卡
         jt.addTab("考试信息管理",testInformation());
         jt.addTab("教师信息管理",teaInformation());
         jt.addTab("学生信息管理",stuInformation());
         jt.setFont(new Font(null,Font.PLAIN,16));
         jf.setContentPane(jt);
         jt.setSize(400,680);
     }
     public JPanel testInformation(){
        JPanel jp = new JPanel();
        jp.setLayout(new BorderLayout());

        Vector header = new Vector();
        header.add("序号");
        header.add("日期");
        header.add("时间");
        header.add("科目");
        header.add("班级");
        header.add("人数");
        header.add("地点");
        header.add("监考员");

        Vector data = testData();

        DefaultTableModel model = new DefaultTableModel(data,header);
        JTable table = new JTable(model);
        table.setFont(new Font("楷体",Font.PLAIN,30));
        //表格不可编辑
        table = new JTable(model){
             public boolean isCellEditable(int row, int column) {
                 return false;
             }
        };
        //使信息居中
        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setHorizontalAlignment(JLabel.CENTER);
        table.setDefaultRenderer(Object.class, r);
        //排序
        RowSorter rs = new TableRowSorter(model);
        table.setRowSorter(rs);

        table.getTableHeader().setReorderingAllowed(false);//表格列不许拖动
        table.setRowHeight(35);//行高
        table.setPreferredScrollableViewportSize(new Dimension(700,600));//滚动面板

        table.getTableHeader().setFont(new Font("楷体",Font.BOLD,20));
        jp.add(table.getTableHeader(),BorderLayout.NORTH);
        jp.add(table,BorderLayout.CENTER);

        JPanel test = testFunction();
        jp.add(test,BorderLayout.SOUTH);
        return  jp;
     }
     private Vector testData() {
         Vector data = new Vector();
         String a;
         try {
             FileReader fr = new FileReader("C:\\Users\\20720\\Desktop\\大作业\\homework\\src\\txt\\考试信息.txt");
             BufferedReader br = new BufferedReader(fr);
             int b = 0, c = 1;
             while ((a = br.readLine()) != null) {
                 String[] d = a.split(" ");        //通过空格分割字符串数组
                 Vector Data = new Vector();
                 Data.add(c);
                 Data.add(d[0]);
                 Data.add(d[1]);
                 Data.add(d[2]);
                 Data.add(d[3]);
                 Data.add(d[4]);
                 Data.add(d[5]);
                 Data.add(d[6]);
                 data.add(Data);
                 b++;
                 c++;
             }
             fr.close();
             br.close();
         } catch (IOException e) {
             e.printStackTrace();
         }
         return data;
     }
     JPanel testFunction(){
         JPanel addtest = new JPanel();
         add_test = new JButton("添加考试信息");
         add_test.addActionListener(this);
         add_test.addActionListener(new ActionListener(){
             @Override
             public void actionPerformed(ActionEvent e) {
                 methodA();
             }
             private void methodA() {

             };
         });
         addtest.add(add_test);

         JPanel deltest = new JPanel();
         del_test = new JButton("删除考试信息");
         del_test.addActionListener(this);
         del_test.addActionListener(new ActionListener(){
             @Override
             public void actionPerformed(ActionEvent e) {
                 methodA();
             }
             private void methodA() {

             }
         });
         deltest.add(del_test);

         JPanel modtest = new JPanel();
         mod_test = new JButton("修改考试信息");
         mod_test.addActionListener(this);
         mod_test.addActionListener(new ActionListener(){
             @Override
             public void actionPerformed(ActionEvent e) {
                 methodA();
             }
             private void methodA() {

             };
         });
         modtest.add(mod_test);

         JPanel jp = new JPanel();
         jp.add(addtest);
         jp.add(deltest);
         jp.add(modtest);
         return jp;
     }
    public JPanel teaInformation(){
        JPanel jp = new JPanel();
        jp.setLayout(new BorderLayout());

        Vector header = new Vector();
        header.add("序号");
        header.add("姓名");
        header.add("账号");
        header.add("密码");

        Vector data = teaData();
        DefaultTableModel model = new DefaultTableModel(data,header);
        JTable table = new JTable(model);
        table.setFont(new Font("楷体",Font.PLAIN,35));

        //表格不可编辑
        table = new JTable(model){
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };

        //使信息居中
        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setHorizontalAlignment(JLabel.CENTER);
        table.setDefaultRenderer(Object.class, r);

        //排序
        RowSorter rs = new TableRowSorter(model);
        table.setRowSorter(rs);

        table.getTableHeader().setReorderingAllowed(false);//表格列不许拖动
        table.setRowHeight(35);//行高
        table.setPreferredScrollableViewportSize(new Dimension(700,600));//滚动面板

        table.getTableHeader().setFont(new Font("楷体",Font.BOLD,20));
        jp.add(table.getTableHeader(),BorderLayout.NORTH);
        jp.add(table,BorderLayout.CENTER);

        JPanel test = teaFunction();
        jp.add(test,BorderLayout.SOUTH);

        return  jp;
    }
    private Vector teaData() {
        Vector data = new Vector();
        String a;
        try {
            FileReader fr = new FileReader("C:\\Users\\20720\\Desktop\\大作业\\homework\\src\\txt\\教师信息.txt");
            BufferedReader br = new BufferedReader(fr);
            int b = 0, c = 1;
            while ((a = br.readLine()) != null) {
                String[] d = a.split(" ");//通过空格分割字符串数组
                Vector Data = new Vector();
                Data.add(c);
                Data.add(d[0]);
                Data.add(d[1]);
                Data.add(d[2]);
                data.add(Data);
                b++;
                c++;
            }
            fr.close();
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return data;
    }
    JPanel teaFunction(){
        JPanel addtea = new JPanel();
        add_tea = new JButton("添加教师信息");
        add_tea.addActionListener(this);
        add_tea.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                methodA();
            }
            private void methodA() {

            };
        });
        addtea.add(add_tea);

        JPanel deltea = new JPanel();
        del_tea = new JButton("删除教师信息");
        del_tea.addActionListener(this);
        del_tea.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                methodA();
            }
            private void methodA() {

            }
        });
        deltea.add(del_tea);

        JPanel modtea = new JPanel();
        mod_tea = new JButton("修改教师信息");
        mod_tea.addActionListener(this);
        mod_tea.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                methodA();
            }
            private void methodA() {

            };
        });
        modtea.add(mod_tea);

        JPanel jp = new JPanel();
        jp.add(addtea);
        jp.add(deltea);
        jp.add(modtea);
        return jp;
    }
    public JPanel stuInformation(){
        JPanel jp = new JPanel();
        jp.setLayout(new BorderLayout());

        Vector header = new Vector();
        header.add("序号");
        header.add("姓名");
        header.add("班级");
        header.add("账号");
        header.add("密码");

        Vector data = stuData();
        DefaultTableModel model = new DefaultTableModel(data,header);
        JTable table = new JTable(model);
        table.setFont(new Font("楷体",Font.PLAIN,35));

        //表格不可编辑
        table = new JTable(model){
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };

        //使信息居中
        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setHorizontalAlignment(JLabel.CENTER);
        table.setDefaultRenderer(Object.class, r);

        //排序
        RowSorter rs = new TableRowSorter(model);
        table.setRowSorter(rs);

        table.getTableHeader().setReorderingAllowed(false);//表格列不许拖动
        table.setRowHeight(35);//行高
        table.setPreferredScrollableViewportSize(new Dimension(700,600));//滚动面板

        table.getTableHeader().setFont(new Font("楷体",Font.BOLD,20));
        jp.add(table.getTableHeader(),BorderLayout.NORTH);
        jp.add(table,BorderLayout.CENTER);

        JPanel test = stuFunction();
        jp.add(test,BorderLayout.SOUTH);

        return  jp;
    }
    private Vector stuData() {
        Vector data = new Vector();
        String a;
        try {
            FileReader fr = new FileReader("C:\\Users\\20720\\Desktop\\大作业\\homework\\src\\txt\\学生信息.txt");
            BufferedReader br = new BufferedReader(fr);
            int b = 0, c = 1;
            while ((a = br.readLine()) != null) {
                String[] d = a.split(" ");//通过空格分割字符串数组
                Vector Data = new Vector();
                Data.add(c);
                Data.add(d[0]);
                Data.add(d[1]);
                Data.add(d[2]);
                Data.add(d[3]);
                data.add(Data);
                b++;
                c++;
            }
            fr.close();
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return data;
    }
    JPanel stuFunction(){
        JPanel addstu = new JPanel();
        add_stu = new JButton("添加学生信息");
        add_stu.addActionListener(this);
        add_stu.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                methodA();
            }
            private void methodA() {

            };
        });
        addstu.add(add_stu);

        JPanel delstu = new JPanel();
        del_stu = new JButton("删除学生信息");
        del_stu.addActionListener(this);
        del_stu.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                methodA();
            }
            private void methodA() {

            }
        });
        delstu.add(del_stu);

        JPanel modstu = new JPanel();
        mod_stu = new JButton("修改学生信息");
        mod_stu.addActionListener(this);
        mod_stu.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                methodA();
            }
            private void methodA() {

            };
        });
        modstu.add(mod_stu);

        JPanel jp = new JPanel();
        jp.add(addstu);
        jp.add(delstu);
        jp.add(modstu);
        return jp;
    }

     public void actionPerformed(ActionEvent e){}
}